<?php

namespace app\api\controller;

use app\admin\business\Category as CategoryBis;
use think\Exception;
use think\facade\Log;
use \app\common\lib\Arr;

class Category extends ApiBase
{
    public function index()
    {
        // 获取所有分类
        try {
            $categorysBusObj = new CategoryBis();
            $categorys = $categorysBusObj->getNormalAllCategorys();
        } catch (\Exception $e) {
            Log::error('内部异常：' . $e->getMessage());
            return show(config("status.success"), "内部异常");
        }
        if (!$categorys) {
            throw new Exception("数据为空");
        }

        $res = Arr::getTree($categorys);
        $res = Arr::sliceTreeArr($res);

        return show(config("status.success"), "OK", $res);
    }

}